<template>
	<view class="">

		<view>
			<image src="https://sxdj.zhiyunapi.com/coach/show/image/co1.jpg" mode="widthFix" style="width: 100%;">
			</image>
		</view>
		<view class="p15 pt10 pb10">

			<u-swiper @click="toInfo" :list="bannerList" height="300" border-radius="10"></u-swiper>
		</view>
		<view>
			<image src="https://sxdj.zhiyunapi.com/coach/show/image/co2.jpg" mode="widthFix" style="width: 100%;">
			</image>
		</view>
		<view class="bg-white pt5 pb12">
			<u-tabs :current="current" :list="tabList" activeStyle="#ee2a2c" :is-scroll="false"
				@change="tabClick">></u-tabs>
			<view class="u-flex module-cate pl15 pr15 mt10">
				<view class="item mr10 fz13" @click="curIndex=index" :class="curIndex==index?'on':''"
					v-for="(item,index) in cateList" :key="index">{{item}}</view>
			</view>
		</view>
		<view @click="toPage('/pages/show/index?img=https://sxdj.zhiyunapi.com/coach/show/image/p1.jpg&title=社区详情')">
			<u-waterfall v-model="flowList" ref="uWaterfall">
				<template v-slot:left="{leftList}">
					<view class="demo-warter" v-for="(item, index) in leftList" :key="index">
						<!-- 警告：微信小程序中需要hx2.8.11版本才支持在template中结合其他组件，比如下方的lazy-load组件 -->
						<u-lazy-load threshold="-450" border-radius="10" :image="item.image"
							:index="index"></u-lazy-load>
						<view class="fz14 mt10">
							{{item.title}}
						</view>
						<view class="demo-shop u-flex u-f-jsb mt5">
							<view class=" u-flex u-f-justify">
								<u-avatar size="40"></u-avatar>
								<view class="ml4">0敏星球</view>
							</view>
							<view class=" u-flex u-f-justify">
								<u-icon name="heart" size="28"></u-icon>
								<view class="ml2">1</view>
							</view>

						</view>
					</view>
				</template>
				<template v-slot:right="{rightList}">
					<view class="demo-warter" v-for="(item, index) in rightList" :key="index">
						<u-lazy-load threshold="-450" border-radius="10" :image="item.image"
							:index="index"></u-lazy-load>
						<view class="fz14 mt10">
							{{item.title}}
						</view>
						<view class="demo-shop u-flex u-f-jsb mt5">
							<view class=" u-flex u-f-justify">
								<u-avatar size="40"></u-avatar>
								<view class="ml4">0敏星球</view>
							</view>
							<view class=" u-flex u-f-justify">
								<u-icon name="heart" size="28"></u-icon>
								<view class="ml2">1</view>
							</view>
						</view>
					</view>
				</template>
			</u-waterfall>

			<u-loadmore bg-color="rgb(240, 240, 240)" :status="loadStatus" @loadmore="addRandomData"></u-loadmore>
		</view>
	</view>
</template>

<script>
	export default {

		data() {
			return {
				
				bannerList: ['https://sxdj.zhiyunapi.com/coach/show/image/banner.jpg',
					'https://sxdj.zhiyunapi.com/coach/show/image/banner.jpg'
				],
				current: 0,
				curIndex: 0,
				tabList: [{
					name: '0敏圈',
				}, {
					name: '0专家说',
				}],
				cateList: ['最新', '最热', '精选', '关注'],

				loadStatus: 'loadmore',
				flowList: [],
				list: [{
						price: 35,
						title: '澳洲LucasPapaw卢卡氏番木瓜膏万用膏25g-膏多用 保湿滋润',

						image: 'https://sxdj.zhiyunapi.com/coach/show/image/pct1.jpg',
					},
					{
						price: 35,
						title: '澳洲LucasPapaw卢卡氏番木瓜膏万用膏25g-膏多用 保湿滋润',

						image: 'https://sxdj.zhiyunapi.com/coach/show/image/pct2.jpg',
					}, {
						price: 35,
						title: '澳洲LucasPapaw卢卡氏番木瓜膏万用膏25g-膏多用 保湿滋润',

						image: 'https://sxdj.zhiyunapi.com/coach/show/image/pct3.jpg',
					}, {
						price: 35,
						title: '澳洲LucasPapaw卢卡氏番木瓜膏万用膏25g-膏多用 保湿滋润',

						image: 'https://sxdj.zhiyunapi.com/coach/show/image/pct4.jpg',
					}, {
						price: 35,
						title: '澳洲LucasPapaw卢卡氏番木瓜膏万用膏25g-膏多用 保湿滋润',

						image: 'https://sxdj.zhiyunapi.com/coach/show/image/pct1.jpg',
					}, {
						price: 35,
						title: '澳洲LucasPapaw卢卡氏番木瓜膏万用膏25g-膏多用 保湿滋润',

						image: 'https://sxdj.zhiyunapi.com/coach/show/image/pct2.jpg',
					}, {
						price: 35,
						title: '澳洲LucasPapaw卢卡氏番木瓜膏万用膏25g-膏多用 保湿滋润',

						image: 'https://sxdj.zhiyunapi.com/coach/show/image/pct3.jpg',
					}, {
						price: 35,
						title: '澳洲LucasPapaw卢卡氏番木瓜膏万用膏25g-膏多用 保湿滋润',

						image: 'https://sxdj.zhiyunapi.com/coach/show/image/pct4.jpg',
					}, {
						price: 35,
						title: '澳洲LucasPapaw卢卡氏番木瓜膏万用膏25g-膏多用 保湿滋润',

						image: 'https://sxdj.zhiyunapi.com/coach/show/image/pct1.jpg',
					},
				]
			}
		},
		onLoad() {
			this.addRandomData();
		},
		onReachBottom() {
			this.loadStatus = 'loading';
			// 模拟数据加载
			setTimeout(() => {
				this.addRandomData();
				this.loadStatus = 'loadmore';
			}, 1000)
		},
		computed: {},
		methods: {

			addRandomData() {
				for (let i = 0; i < 10; i++) {
					let index = this.$u.random(0, this.list.length - 1);
					// 先转成字符串再转成对象，避免数组对象引用导致数据混乱
					let item = JSON.parse(JSON.stringify(this.list[index]))
					item.id = this.$u.guid();
					console.log(item)
					this.flowList.push(item);
				}
			},
			remove(id) {
				this.$refs.uWaterfall.remove(id);
			},
			clear() {
				this.$refs.uWaterfall.clear();
			},
			tabClick(e) {
				this.current = e
				console.log(e)
			},
			toPage(url) {
				uni.navigateTo({
					url
				})
			},
		}
	}
</script>

<style lang="scss">
	.module-cate {
		.item {
			border-radius: 50rpx;
			border: 1px solid #666;
			color: #222;
			padding: 4rpx 15rpx;

			&.on {
				border: 1px solid #ee2a2c;
				color: #ee2a2c;
			}
		}
	}
</style>

<style>
	/* page不能写带scope的style标签中，否则无效 */
	page {
		background-color: rgb(240, 240, 240);
	}
</style>

<style lang="scss" scoped>
	.demo-warter {
		border-radius: 8px;
		margin: 5px;
		background-color: #ffffff;
		padding: 10px;
		position: relative;
	}

	.u-close {
		position: absolute;
		top: 32rpx;
		right: 32rpx;
	}

	.demo-image {
		width: 100%;
		border-radius: 4px;
	}

	.demo-title {
		font-size: 30rpx;
		margin-top: 5px;
		color: $u-main-color;
	}

	.demo-tag {
		display: flex;
		margin-top: 5px;
	}

	.demo-tag-owner {
		background-color: $u-type-error;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		padding: 4rpx 14rpx;
		border-radius: 50rpx;
		font-size: 20rpx;
		line-height: 1;
	}

	.demo-tag-text {
		border: 1px solid $u-type-primary;
		color: $u-type-primary;
		margin-left: 10px;
		border-radius: 50rpx;
		line-height: 1;
		padding: 4rpx 14rpx;
		display: flex;
		align-items: center;
		border-radius: 50rpx;
		font-size: 20rpx;
	}

	.demo-price {
		font-size: 30rpx;
		color: $u-type-error;
		margin-top: 5px;
	}

	.demo-shop {
		font-size: 22rpx;
		color: $u-tips-color;
		margin-top: 5px;
	}
</style>